<?php

/**
 * OrganisationalEntity form.
 *
 * @package    wildlive
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class OrganisationalEntityForm extends BaseOrganisationalEntityForm
{
  public function configure()
  {
  	unset(
  		$this['slug'],
  		$this['deleted_at'],
  		$this['created_at'],
  		$this['updated_at'],
  		$this['deleted_by'],
  		$this['created_by'],
  		$this['updated_by'],
  		$this['lft'],
  		$this['rgt'],
  		$this['level'],
  		$this['root_id']);
  	
  	$this->setWidget('parent_id', new sfWidgetFormDoctrineChoice(array('model' => 'OrganisationalEntity', 'add_empty' => 'ohne Parent')));
//  	$this->setValidator('parent_id', 
//  		new sfValidatorAnd(array(
//  			new sfValidatorDoctrineChoice(array('model' => 'OrganisationalEntity', 'required' => false)),
//  			new sfValidatorOr(array(
//  				new ValidatorOrganisationalEntityCanHaveChildren(array('required' => false)),
//  				new sfValidatorString(array('max_length' => 0, 'required' => false)))))));
  	$this->setValidator('parent_id', 
  		new sfValidatorOr(array(
  				new ValidatorOrganisationalEntityCanHaveChildren(array('required' => false)),
  				new ValidatorEmpty()))); #sfValidatorString(array('max_length' => 0, 'required' => false)))));
    if($this->getObject()->getNode()->getParent()) {
    	$this->setDefault('parent_id', $this->getObject()->getNode()->getParent()->getId());
    }
    
    $choices = array('federal' => 'Bund', 'state' => 'Landesverband', 'regional' => 'Bezirk', 'aerie' => 'Horst', 'chapter' => 'Stamm');
    $this->setWidget('type', new sfWidgetFormChoice(array('choices' => $choices)));
  	$this->setValidator('type', new sfValidatorChoice(array('choices' => array_flip($choices), 'required' => true)));
    
    $this->setWidget('age_group_id', new sfWidgetFormDoctrineChoice(array('model' => 'AgeGroup', 'add_empty' => true)));
  	$this->setValidator('age_group_id', new sfValidatorDoctrineChoice(array('model' => 'AgeGroup', 'required' => false)));
  	$this->widgetSchema->setHelp('age_group_id', 'nur bei Gruppen benötigt');
  }
}